﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TankGameV1._0
{
    class BulletObeject : GameObject
    {
        //子弹父类需要子弹的图片
        private Image image;

        public Image Image { get => image; set => image = value; }
        public int Power
        {
            get;
            set;
        }
        //子弹需要速度，生命值，方向
        public BulletObeject(TankObject tankObject,int speed,int life , int power,Image image)
            : base(tankObject.X + tankObject.Width / 2 - 6, tankObject.Y + tankObject.Height / 2 - 6,speed, image.Width, image.Height, life, tankObject.Dir)
        {
            this.image = image;
            this.Power = power;
        }

        public override void Draw(Graphics g)
        {
            switch (this.Dir)
            {   //如果坦克向上移动其纵坐标要减小,且减小的是其速度大小
                case Direction.Up:
                    this.Y -= this.Speed;
                    break;
                case Direction.Down:
                    this.Y += this.Speed;
                    break;
                case Direction.Left:
                    this.X -= this.Speed;
                    break;
                case Direction.Right:
                    this.X += this.Speed;
                    break;
            }
            //要判断坦克是否出界
            if (this.X <= -100)
            {
                this.X = -100;
            }
            if (this.X >= 1100)
            {
                this.X = 1100;
            }
            if (this.Y <= -100)
            {
                this.Y = -100;
            }
            if (this.Y >= 900)
            {
                this.Y = 900;
            }
            g.DrawImage(image, this.X, this.Y);
        }
    }
}
